//
//  GYOrderEvaluateTableViewCell.m
//  GoodLuck
//
//  Created by apple on 2018/3/23.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYOrderEvaluateTableViewCell.h"


static NSString *orderEvaluateCellIdentifier = @"orderEvaluateCellIdentifier";

@interface GYOrderEvaluateTableViewCell ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *goodsImageView;
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLable;

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *goodsScoreBtus;


@property (weak, nonatomic) IBOutlet UIImageView *isAnonymousImageView;
@property (weak, nonatomic) IBOutlet UIButton *anonymousBtu;

@property (weak, nonatomic) IBOutlet UITextField *goodsEvaluateTF;



@end

@implementation GYOrderEvaluateTableViewCell


+ (instancetype)cellWithtTableview:(UITableView *)tableView {
    GYOrderEvaluateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:orderEvaluateCellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] firstObject];
    }
    
    return cell;
}

//商品评分按钮点击事件
- (IBAction)goodScoreBtuClick:(UIButton *)sender {
    for (int i = 0; i<self.goodsScoreBtus.count; i++) {
        UIButton *btu = self.goodsScoreBtus[i];
        if (i <= sender.tag-1) {
            btu.selected = YES;
        }else {
            btu.selected = NO;
        }
    }
    self.cachesGoodsScoreCallBack(sender.tag);
}

//是否匿名评论
- (IBAction)anonymousBtuClick:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    if (sender.selected) {
        self.isAnonymousImageView.image = [UIImage imageNamed:@"xuanzhong"];
    }else {
        self.isAnonymousImageView.image = [UIImage imageNamed:@"weixuanzhong"];
    }
}

//选择图片
- (IBAction)selectImageViewBtuClick:(UIButton *)sender {
    self.updateSelectBtuCallBack(sender, self.anonymousBtu.selected, self.goodsEvaluate.goods_id);
}

- (void)setGoodsEvaluate:(GYOrderGoods *)goodsEvaluate {
    _goodsEvaluate = goodsEvaluate;
    
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:goodsEvaluate.goods_image_url] placeholderImage:[UIImage imageNamed:@"4"]];
    self.goodsNameLable.text = goodsEvaluate.goods_name;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.goodsEvaluateTF addTarget:self action:@selector(endEdit) forControlEvents:UIControlEventEditingDidEndOnExit];
}

- (void)endEdit {
    [self endEditing:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    self.cachesGoodsEvalauteCallBack(textField.text == nil ? @"" : textField.text);
}

@end
